home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / sys / amiga / src / pla_pr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-23  |  5.4 KB  |  213 lines

  1. /* $Id: pla_pr.c,v 1.4 1994/03/23 08:56:15 mjl Exp $
  2.    $Log: pla_pr.c,v $
  3.  * Revision 1.4  1994/03/23  08:56:15  mjl
  4.  * Header file rearrangement, also removed some redundant variable clears.
  5.  *
  6.  * Revision 1.3  1993/07/31  07:56:55  mjl
  7.  * Several driver functions consolidated, for all drivers.  The width and color
  8.  * commands are now part of a more general "state" command.  The text and
  9.  * graph commands used for switching between modes is now handled by the
  10.  * escape function (very few drivers require it).  The device-specific PLDev
  11.  * structure is now malloc'ed for each driver that requires it, and freed when
  12.  * the stream is terminated.
  13.  *
  14.  * Revision 1.2  1993/07/01  21:59:53  mjl
  15.  * Changed all plplot source files to include plplotP.h (private) rather than
  16.  * plplot.h.  Rationalized namespace -- all externally-visible plplot functions
  17.  * now start with "pl"; device driver functions start with "plD_".
  18. */
  19.  
  20. /*    pla_pr.c
  21.  
  22.     PLPLOT Amiga (preferences) printer device driver.
  23.     Most of the code is in plsupport.c where it is shared with the
  24.     menu selection printer dump.
  25. */
  26.  
  27. #include "plplotP.h"
  28. #include "drivers.h"
  29. #include "plamiga.h"
  30.  
  31. /* top level declarations */
  32.  
  33. static long bmapx, bmapy, bmapxmax, bmapymax, xdpi, ydpi;
  34. static long dwidth, dheight;
  35.  
  36. /*----------------------------------------------------------------------*\
  37. * plD_init_amipr()
  38. *
  39. * Initialize device.
  40. \*----------------------------------------------------------------------*/
  41.  
  42. void
  43. plD_init_amipr(PLStream *pls)
  44. {
  45.     PLDev *dev;
  46.     int mode;
  47.  
  48.     pls->termin = 0;        /* not an interactive terminal */
  49.     pls->icol0 = 1;
  50.     pls->width = 1;
  51.     pls->bytecnt = 0;
  52.     pls->page = 0;
  53.  
  54.     if (!pls->colorset)
  55.         pls->color = 0;        /* no color by default: user can override */
  56.  
  57.     if (openprinter())
  58.     plexit("");
  59.  
  60.     mode = queryprint(&bmapx, &bmapy, &bmapxmax, &bmapymax, &xdpi, &ydpi);
  61.  
  62. /* If mode == 1 we want to adjust the bitmap size so that the aspect
  63.    ratio is maintained. 
  64. */
  65.     if (mode) {
  66.     if ((float) bmapxmax * bmapy > (float) bmapymax * bmapx)
  67.         bmapy = (int) (((float) bmapx * bmapymax) / bmapxmax + .5);
  68.     else
  69.         bmapx = (int) (((float) bmapy * bmapxmax) / bmapymax + .5);
  70.     }
  71.  
  72. /* Leave a little space for pen width. */
  73.  
  74.     dwidth = bmapx - 2;
  75.     dheight = bmapy - 2;
  76.  
  77. /* Allocate and initialize device-specific data */
  78.  
  79.     dev = plAllocDev(pls);
  80.  
  81.     dev->xold = UNDEFINED;
  82.     dev->yold = UNDEFINED;
  83.     dev->xmin = 0;
  84.     dev->xmax = bmapxmax;
  85.     dev->ymin = 0;
  86.     dev->ymax = bmapymax;
  87.  
  88.     plP_setpxl((ydpi / 25.4), (xdpi / 25.4));
  89.     plP_setphy(0, bmapymax, 0, bmapxmax);
  90.  
  91. /* Allocate bitmap and initial for line drawing */
  92.  
  93.     if (mapinit(bmapx, bmapy)) {
  94.     closeprinter();
  95.     plexit("");
  96.     }
  97. }
  98.  
  99. /*----------------------------------------------------------------------*\
  100. * plD_line_amipr()
  101. *
  102. * Draw a line in the current color from (x1,y1) to (x2,y2).
  103. \*----------------------------------------------------------------------*/
  104.  
  105. void 
  106. plD_line_amipr(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
  107. {
  108.     PLDev *dev = (PLDev *) pls->dev;
  109.     int x1=x1a, y1=y1a, x2=x2a, y2=y2a;
  110.     long xn1, yn1, xn2, yn2;
  111.  
  112.     xn1 = (x1 * dheight) / bmapymax;
  113.     yn1 = (y1 * dwidth) / bmapxmax;
  114.     xn2 = (x2 * dheight) / bmapymax;
  115.     yn2 = (y2 * dwidth) / bmapxmax;
  116.     switch (pls->width) {
  117.     case 3:
  118.     mapline(yn1, xn1, yn2, xn2);
  119.     case 2:
  120.     mapline(yn1 + 2, xn1 + 2, yn2 + 2, xn2 + 2);
  121.     case 1:
  122.     default:
  123.     mapline(yn1 + 1, xn1 + 1, yn2 + 1, xn2 + 1);
  124.     }
  125. }
  126.  
  127. /*----------------------------------------------------------------------*\
  128. * plD_polyline_amipr()
  129. *
  130. * Draw a polyline in the current color.
  131. \*----------------------------------------------------------------------*/
  132.  
  133. void 
  134. plD_polyline_amipr (PLStream *pls, short *xa, short *ya, PLINT npts)
  135. {
  136.     PLINT i;
  137.  
  138.     for (i=0; i<npts-1; i++) 
  139.       plD_line_amipr( pls, xa[i], ya[i], xa[i+1], ya[i+1] );
  140. }
  141.  
  142. /*----------------------------------------------------------------------*\
  143. * plD_eop_amipr()
  144. *
  145. * End of page. 
  146. \*----------------------------------------------------------------------*/
  147.  
  148. void 
  149. plD_eop_amipr(PLStream *pls)
  150. {
  151.     dmpport(0L, bmapx, bmapy);
  152.     /* Eject the page. */
  153.     ejectpage();
  154. }
  155.  
  156. /*----------------------------------------------------------------------*\
  157. * plD_bop_amipr()
  158. *
  159. * Set up for the next page.  
  160. * Advance to next family file if necessary (file output).
  161. \*----------------------------------------------------------------------*/
  162.  
  163. void 
  164. plD_bop_amipr(PLStream *pls)
  165. {
  166.     mapclear();
  167.     pls->page++;
  168. }
  169.  
  170. /*----------------------------------------------------------------------*\
  171. * plD_tidy_amipr()
  172. *
  173. * Close graphics file or otherwise clean up.
  174. \*----------------------------------------------------------------------*/
  175.  
  176. void 
  177. plD_tidy_amipr(PLStream *pls)
  178. {
  179.     mapfree();
  180.     closeprinter();
  181. }
  182.  
  183. /*----------------------------------------------------------------------*\
  184. * plD_state_amipr()
  185. *
  186. * Handle change in PLStream state (color, pen width, fill attribute, etc).
  187. \*----------------------------------------------------------------------*/
  188.  
  189. void 
  190. plD_state_amipr(PLStream *pls, PLINT op)
  191. {
  192.     switch (op) {
  193.  
  194.       case PLSTATE_WIDTH:
  195.     if (pls->width < 1)
  196.         pls->width = 1;
  197.     else if (pls->width > 3)
  198.         pls->width = 3;
  199.     break;
  200.     }
  201. }
  202.  
  203. /*----------------------------------------------------------------------*\
  204. * plD_esc_amipr()
  205. *
  206. * Escape function.
  207. \*----------------------------------------------------------------------*/
  208.  
  209. void 
  210. plD_esc_amipr(PLStream *pls, PLINT op, char *ptr)
  211. {
  212. }
  213.